project(example)

find_package(Boost REQUIRED COMPONENTS filesystem)

function(add_example TARGET DIR)
    set(cppnames "" PARENT_SCOPE)
    foreach(cppname ${ARGN})
        # message("append: " ${cppname})
        list(APPEND cppnames ${DIR}/${cppname})
    endforeach()
    # message("cppnames: " ${cppnames})

    add_executable(${TARGET} ${cppnames})
    target_link_libraries(${TARGET}
    	PRIVATE
	${Boost_LIBRARIES}
    )
    target_include_directories(${TARGET}
        PRIVATE
        ${Boost_INCLUDEDIR}
    )

    target_include_directories(${TARGET}
	PRIVATE
        ${CMAKE_SOURCE_DIR}/include
	${Boost_INCLUDEDIR}
    )
endfunction(add_example DIR TARGET)

add_example(args . args.cpp)
add_example(async_io . async_io.cpp)
add_example(env . env.cpp)
add_example(error_handling . error_handling.cpp)
add_example(intro . intro.cpp)
add_example(io . io.cpp)
add_example(posix . posix.cpp)
add_example(sync_io . sync_io.cpp)
add_example(terminate . terminate.cpp)
add_example(wait . wait.cpp)
add_example(multithreaded_async_pipe . multithreaded_async_pipe.cpp)

add_example(start_dir . start_dir.cpp)
add_example(v2_intro v2 intro.cpp)
add_example(v2_intro_popen v2 intro_popen.cpp)

if (WIN32)
add_example(windows . windows.cpp)
endif (WIN32)
